/*
 * Copyright 2012 SerGenis. All rights reserved.
 */
package com.sergenis.form;

import com.sergenis.util.SerialClone;

/**
 * @author SerGenis
 * @deprecated 
 */
public class FormControlSync<T>
    extends FormCollection<T> {

    private int indexBackup;

    public int getIndexBackup() {
	return indexBackup;
    }

    public void setIndexBackup(int indexBackup) {
	this.indexBackup = indexBackup;
    }
    protected T backup;
    public static final String PROP_BACKUP = "backup";

    public T getBackup() {
	return backup;
    }

    public void setBackup(T backup) {
	T oldBackup = this.backup;
	this.backup = backup;
	firePropertyChange(PROP_BACKUP, oldBackup, backup);
    }

    public T prepareBackup(int index) {
	T ori = get(index);
	T clone = SerialClone.clone(ori);
	setBackup(clone);
	indexBackup = index;
	return ori;
    }

    public int restoreBackup() {
	set(indexBackup, backup);
	return delateBackup();
    }

    public int delateBackup() {
	int oldIndex = indexBackup;
	this.indexBackup = -1;
	this.backup = null;
	return oldIndex;
    }
}
